<?php
/**
 * Created by PhpStorm.
 * User: mars
 * Date: 2019/1/27
 * Time: 1:05 PM
 */

namespace api\controllers;


use api\models\Banner;
use api\models\Options;
use yii\web\ServerErrorHttpException;
use Yii;
class BannerController extends BaseController
{

    public $modelClass = "api\models\Banner";

    public function actions()
    {
        $actions = parent::actions();
        unset($actions['index']);

        return $actions;
    }


    //
    public function actionBanner($type)
    {
        if (isset($type)) {
            $model = Banner::getBannersByType($type);

            return $model;
        }
        throw new ServerErrorHttpException('Failed to find the banners for this type.');
    }

    //公告
    public function actionSettings()
    {
        $settings = Options::find()->where(['type' => Options::TYPE_CUSTOM])->orderBy("sort")->indexBy('id')->all();

        return $settings;
    }

    public function actionAds($name)
    {
        if (isset($name)) {
            $model = Options::getAdByName($name);

            return $model;
        }
        throw new ServerErrorHttpException('Failed to find the ad for this name.');
    }


}